package test.annotation;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.Random;


 // 
/**
 * http://blog.csdn.net/haveferrair/article/details/52182927
 * 
 * 
 * http://www.jianshu.com/p/d294bf008bec
 * https://moxun.me/archives/63
 * @author yw
 *
 */
public class AutoCallMain {
	static String[] dj = new String[] {
		"你好，有什么我能帮你的吗？",
		"你有什么需要我做的吗？",
		"有什么指示吗？",
		"需要我为你做点什么?"
	};
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub	
		TestA a = new TestA("robot");
		Random random = new Random();
		String input = null;
		
		while (true){
			System.out.println(dj[random.nextInt(4)]);
			
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			try {
				input = br.readLine();
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			
			Method m = a.findMethod(input);
			if (m == null){
				System.out.println("并没有这个 方法");
				continue;
			}
//			Method m = a.findMethod("打电话");
//			System.out.println("m=" + m + "\t input=" + input);
			AutoCall autoCall = m.getDeclaredAnnotation(AutoCall.class);
			
			
			if (!"".equals(autoCall.tip())){
				System.out.println(autoCall.tip());
				
				try {
					input = br.readLine();
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
				String[] ss = input.split(" ");
				a.CallFunc(m, (Object)ss);
			}else {
				a.CallFunc(m);
			}
			
			try {
				Thread.currentThread().sleep(50);
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}//end of "while(..."
	}

}
